import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        System.out.println("你好，欢迎来到猜数字游戏,请输入一个1-100之间的数字");
        Random r = new Random();
        Scanner scan = new Scanner(System.in);
        System.out.print("您的答案:");
        int answer = r.nextInt(100) + 1;
        int iNumber = scan.nextInt();
        int count =7;
        while (count>0) {
            if (answer != iNumber) {
                if(answer>iNumber){
                    System.out.println("您猜的数字为: " + iNumber +"\n答案相对于你的数字偏小"+"\n请您再次尝试,您还有"+count+"次机会!");
                }
                else{
                    System.out.println("您猜的数字为: " + iNumber +"\n答案相对于你的数字偏大"+"\n请您再次尝试,您还有"+count+"次机会!");
                }
                System.out.print("您的答案:");
                iNumber = scan.nextInt();
            } else {
                System.out.println("您猜的数字为: " + iNumber + " 答案为:" + answer + "\n您猜对了,用了"+count+"次机会");
                break;
            }
            count--;
            if(count==0){
                System.out.println("次数用尽,游戏结束!");
                System.out.println("是否重新开始? 提示:重新开始输入Y,结束输入N");
                String decide = scan.next();
                if(decide.equals("Y")){
                    count=6;
                    answer = r.nextInt(100) + 1;
                    System.out.print("您的答案:");
                    iNumber = scan.nextInt();
                }
                else if(decide.equals("N")) {
                    System.out.println("再见，祝您下次玩的开心哦!");
                }
            }
        }
    }
}
